package com.xneure.function.enums;

import java.sql.Date;
import java.sql.Time;
import java.util.Arrays;
import com.xneure.utils.ObjectUtil;

public enum ParamType{
	UNKNOWN("未知"){
		@Override
		public Object format(Object val){
			return val;
		}
	},
	STRING("字符串"){
		@Override
		public Object format(Object _val){
			if(ObjectUtil.isNull(_val)){
				return null;
			}
			String val = _val.toString();
			int s = 0, e = val.length();
			if(val.charAt(0) == '"'){
				++s;
			}
			if(val.charAt(val.length() - 1) == '"'){
				--e;
			}
			return String.valueOf(Arrays.copyOfRange(val.toCharArray(),s,e));
		}
	},
	DOUBLE("浮点数"){
		@Override
		public Object format(Object val){
			return ObjectUtil.convertValue(val,Double.class);
		}
	},
	DATE("日期"){
		@Override
		public Object format(Object val){
			return ObjectUtil.convertValue(val,Date.class);
		}
	},
	TIME("时间"){
		@Override
		public Object format(Object val){
			return ObjectUtil.convertValue(val,Time.class);
		}
	},
	LONG("整形"){
		@Override
		public Object format(Object val){
			return ObjectUtil.convertValue(val,Long.class);
		}
	},;
	private String title;

	ParamType(String t){
		title = t;
	}

	public String getTitle(){
		return title;
	}

	public abstract Object format(Object val);
}
